package com.he.architecture.controller;

import com.he.architecture.common.controller.LogicController;
import com.he.architecture.dao.ItemDao;
import com.he.architecture.dto.ResponseResult;
import com.he.architecture.dto.ShopWithItemResponseDto;
import com.he.architecture.entity.Item;
import com.he.architecture.service.BusinessService;
import com.he.architecture.service.ItemService;
import com.he.architecture.service.ShopItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/item")
public class ItemController extends LogicController<ItemService, ItemDao, Item, Long> {
    @Resource
    BusinessService businessService;
    public ItemController(@Autowired ItemService service) {
        super(service);
    }
    @GetMapping("/getItemsByBusinessId")
    public ResponseResult getItemsByBusinessId(@RequestParam("bus_id") Long bus_id) {
        //获取门店id列表
        List<Long> shopIds =businessService.getShopIds(bus_id);
        //获取
        List<ShopWithItemResponseDto> responseDtos=getService().getItemsByShopIds(shopIds);
        Map<String,Object> map=new HashMap<>();
        map.put("responseDtos",responseDtos);
        return new ResponseResult(200,map);
    }
    @GetMapping("/getItemsByShopId")
    public ResponseResult getItemsByShopId(@RequestParam("shop_id") Long shop_id){
        List<Item> items = getService().getItemsByShopId(shop_id);
        Map<String,Object> map=new HashMap<>();
        map.put("items",items);
        return new ResponseResult(200,map);
    }
}
